package com.cn.longdistancebusstation.ui;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.cn.longdistancebusstation.R;
import com.cn.longdistancebusstation.base.BaseActivity;
import com.cn.longdistancebusstation.fragment.ComplishFragment;
import com.cn.longdistancebusstation.fragment.UncomplishFragment;

/**
 * Created by Administrator on 2018/1/16.
 */

public class MyOrderActivity extends BaseActivity implements View.OnClickListener{
    private Fragment mfragmentContent;

    private ImageView mBackImageView;
    private TextView mConvinceTipsTextView;
    private TextView mCallTextView;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getSupportActionBar().hide();
        setContentView(R.layout.activity_myorder);
        initview();
    }

    private void initview() {
        mBackImageView=(ImageView)findViewById(R.id.sc_back);
        mBackImageView.setOnClickListener(this);
        mConvinceTipsTextView=(TextView)findViewById(R.id.btn_complish);
        mConvinceTipsTextView.setOnClickListener(this);
        mCallTextView=(TextView)findViewById(R.id.btn_uncomplish);
        mCallTextView.setOnClickListener(this);

        // 设置默认显示已完成界面
        if (mfragmentContent == null) {
            mfragmentContent = new ComplishFragment();
        }
        switchConent(mfragmentContent);


    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.sc_back:
                finish();
                break;
            case R.id.btn_complish:
                resetAll();
                /**
                 * 将消息Fragment显示出来
                 * 将图片换成蓝色的图片
                 */
                mfragmentContent = new ComplishFragment();

                mConvinceTipsTextView.setBackgroundResource(R.mipmap.choose_pro_2_all);
                mConvinceTipsTextView.setTextColor(getResources().getColor(R.color.themeColor));
                break;
            case R.id.btn_uncomplish:
                resetAll();
                mfragmentContent = new UncomplishFragment();
                mCallTextView.setBackgroundResource(R.mipmap.choose_pro_1_my);
                mCallTextView.setTextColor(getResources().getColor(R.color.themeColor));
                break;
        }
        if (mfragmentContent != null) {
            switchConent(mfragmentContent);
        }

    }
    /**
     * 切换Fragment
     *
     * @param fragment
     */
    public void switchConent(Fragment fragment) {
        mfragmentContent = fragment;
        getSupportFragmentManager().beginTransaction()
                .replace(R.id.cs_frame_layout, mfragmentContent).commit();
    }
    /**
     * 将所有的Fragment隐藏
     * 将所有的图片设置为不选中
     */
    public void resetAll() {
        mConvinceTipsTextView.setBackgroundResource(R.mipmap.choose_pro_1_all);
        mConvinceTipsTextView.setTextColor(getResources().getColor(R.color.white));

        mCallTextView.setBackgroundResource(R.mipmap.choose_pro_2_my);
        mCallTextView.setTextColor(getResources().getColor(R.color.white));
    }

}
